package com.cloud.school.bus.teacherhelper.modules.init;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.apache.http.Header;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;

import com.android.support.jhf.debug.DebugLog;
//import com.alipay.android.app.sdk.AliPay;
import com.android.support.jhf.handlerui.HandlerPostUI;
import com.android.support.jhf.network.NetworkClient;
import com.android.support.jhf.network.loopj.android.http.ResponseHandlerInterface;
import com.android.support.jhf.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.android.support.jhf.utils.FileUtils;
import com.cloud.school.bus.teacherhelper.base.Constant;
import com.cloud.school.bus.teacherhelper.base.activity.BaseActivity;
import com.cloud.school.bus.teacherhelper.base.utils.SaveUserOperate;
import com.cloud.school.bus.teacherhelper.include.Version;
import com.cloud.school.bus.teacherhelper.modules.SlidingActivity;
import com.cloud.school.bus.teacherhelper.modules.login.LoginActivity;
import com.cloud.school.bus.teacherhelper.R;
import com.umeng.analytics.MobclickAgent;

/**
 * 初始化界面
 * 
 * @author lenovo
 * 
 */
public class InitActivity extends BaseActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		if (mApplication.mFlagHome) {
			finish();
			return;
		}

		setContentView(R.layout.activity_init);

		mApplication.mFlagHome = true;

		ExecutorService executorService = Executors.newSingleThreadExecutor();
		executorService.execute(new Runnable() {

			@Override
			public void run() {

				try {
					TimeUnit.SECONDS.sleep(1);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}

				HandlerPostUI.getHandlerPostUI(new Runnable() {

					@Override
					public void run() {
						goActivity();
					}
				});
			}
		});

	}

	/**
	 * 跳转页面
	 */
	private void goActivity() {
		// 跳转到首页
		Intent intent = new Intent(mContext, LoginActivity.class);
		startActivity(intent);
		finish();
		overridePendingTransition(android.R.anim.fade_in,
				android.R.anim.fade_out);
	}
	
	private void quit() {
		System.exit(0);
		finish();
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(keyCode == KeyEvent.KEYCODE_BACK){
			quit();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}
	
}
